package com.bbt.dormassistant.controller;

import com.bbt.dormassistant.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;


@Api(tags = "公告接口")
@RestController
@RequestMapping("/notice")
public class NoticeController {


    @Autowired
    NoticeService noticeService;


    @ApiOperation(value = "添加一篇新的告示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "String"),
            @ApiImplicitParam(name = "tittle", value = "标题", required = true, dataType = "String"),
            @ApiImplicitParam(name = "text", value = "内容", required = true, dataType = "String")

    })
    @PostMapping("/addNotice")
    public Map<String,Object> addNotice(@RequestParam(value = "userId") String userId,
                                        @RequestParam(value = "tittle") String tittle,
                                        @RequestParam(value = "text") String text){
        Map<String,Object> map = new HashMap<>();
        map.put("success",noticeService.addNotice(userId,tittle,text));
        return map;
    }



    @ApiOperation(value = "根据告示ID删除告示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "noticeId", value = "告示ID", required = true, dataType = "int")
    })
    @PostMapping("/deleteNoticeById")
    public Map<String,Object> deleteNoticeById(@RequestParam("noticeId") Integer noticeId){
        Map<String,Object> map = new HashMap<>();
        map.put("success",noticeService.deleteNotice(noticeId));
        return map;
    }



    @ApiOperation(value = "获取所有告示")
    @GetMapping("/queryAllNotice")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currIndex", value = "当前页码(可选项)", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "页大小(可选项)",  dataType = "int")
    })
    public Map<String,Object> queryAllNotice(@RequestParam(value = "currIndex",required = false) Integer currIndex,
                                             @RequestParam(value = "pageSize",required = false) Integer pageSize){
        Map<String,Object> noticeMap = new HashMap<>();
        noticeMap.put("notices",noticeService.queryAllNotice(currIndex,pageSize));
        return noticeMap;
    }


}
